package grp.test.controller;

import grp.test.common.ServerResponse;
import grp.test.pojo.Book;
import grp.test.service.ISearchSeverice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2020/8/15.
 */
@Controller
@RequestMapping("/search/")

public class SearchController {
    @Autowired
    ISearchSeverice iBookService;

////    模糊查询，通过书的描述
//    @RequestMapping(value = "searchBookList.do", method = RequestMethod.POST)
//    @ResponseBody
//    public ServerResponse<List<Book>> getBookList(String des) {
//
//        if (des==null)
//        {
//            return ServerResponse.createByErrorMessage("描述关键字不能为空");
//        }
//        return iBookService.getBookList(des);
//    }

    //模糊查询，通过书名/简介
    @RequestMapping(value = "searchBookListName.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<List<Book>> getBookList(String bookname, String des)  {

        if (bookname == null && des == null) {
            return ServerResponse.createByErrorMessage("关键字不能为空！");
        }
        System.out.println(bookname);
        System.out.println(des);
        return iBookService.getBookList(bookname,des);
    }
//    点击查看（通过id查询）
    @RequestMapping(value = "checkBook.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Book> checkBook(Integer bookId) {

        if (bookId == null) {
            return ServerResponse.createByErrorMessage("关键字不能为空！");
        }
        return iBookService.getBook(bookId);
    }

}
